﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddHistoryCustomer.aspx.cs" Inherits="ZX.WebApp.Crm.Customer.AddHistoryCustomer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/inputDate.js" type="text/javascript"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.calendar.js" type="text/javascript"></script>
    <link href="../../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
</head>
<body class="yui-skin-sam" onkeydown="PreventBSK()">
    <form id="form1" runat="server">
    <div id="toolbar" style="margin-top: 3px;">
        <button type="button" id="btnClose" name="btnClose">
            退出</button>
        <button type="button" id="btnSave" name="btnSave">
            保存</button>
    </div>
    <div class="fieldForm" id="fieldForm">
        <table class="tableContent" id="tableContent">
            <tr>
                <td colspan="6"><span style="color:Blue;">客户信息</span></td>
            </tr>
            <tr>
                <td width="11%">
                    <asp:HiddenField ID="ID" runat="server" />
                    &nbsp;客户编码：<span id="spanCode" style="color: Red;">*</span>
                </td>
                <td>
                    <input runat="server" type="text" id="Code" name="Code" readonly="readonly" 
                        style="width: 150px; background-color:#e7eaf4;" />
                </td>
                <td width="11%">
                    &nbsp;信息专员：<span style="color: Red">*</span>
                </td>
                <td>
                    <span style='color: #FF0000'>
                        <input type="hidden" runat="server" id="AddUserId" name="AddUserId" />
                        <input runat="server" type="text" id="txtAddUserId" name="txtAddUserId" readonly="readonly"
                            style="width: 150px; background-color:#e7eaf4;" />
                        <button id="btnAddUserId" name="Z" type="button" class="btnCheck" style="width:50px;">
                            选择</button>
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;行销顾问：<span style="color: Red">*</span>
                </td>
                <td colspan="5">
                    <span style='color: #FF0000'>
                        <input type="hidden" id="SaleadviserId" runat="server" />
                        <input runat="server" type="text" id="txtSaleadviserId" name="txtSaleadviserId" readonly="readonly"
                            style="width: 150px; background-color:#e7eaf4;" />
                        <button id="btnSaleadviserId" name="Z" type="button" class="btnCheck" style="width:50px;">
                            选择</button>
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;客户名称：<span style="color: Red">*</span>
                </td>
                <td colspan="3">
                    <input runat="server" type="text" id="CustomerName" name="CustomerName" 
                        onKeyDown="showSetNum('CustomerName','ShowCustoemrName',50)" 
                        onKeyUp="showSetNum('CustomerName','ShowCustoemrName',50)" 
                        onblur="ValidateCustomerNameFullNumber(this.value,'客户名称','CustomerName','ShowCustoemrName');"
                        style="width: 255px;" />
                    <img id="btnCheckCustomerName" onclick="CheckCustomerName()" title="检查客户名称是否可用?" 
                        alt="检查客户名称是否可用?"
                        src="../../Images/search01.png" style="cursor:hand; vertical-align:bottom;" />
                    <span class="span_font">(0-50字)请填写完整公司全称</span>
                    <span class="span_font" id="ShowCustoemrName"></span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;公司地址：<%--<span style="color: Red">*</span>--%>
                </td>
                <td colspan="3">
                    <asp:DropDownList ID="State" name="State" runat="server" Width="80" AppendDataBoundItems="true">
                        <asp:ListItem Value="中国">中国</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="Province" name="Province" runat="server" Width="80" AppendDataBoundItems="true">
                        <asp:ListItem Value=" ">选择省份</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="City" name="City" runat="server" Width="80" AppendDataBoundItems="true">
                        <asp:ListItem Value=" ">选择城市</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="Area" name="Area" runat="server" Width="80" AppendDataBoundItems="true">
                        <asp:ListItem Value=" ">选择区县</asp:ListItem>
                    </asp:DropDownList>
                    <input runat="server" type="text" id="Address" name="Address" size="100" maxlength="100"
                        style="width: 21%;" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;决策人姓名：<span style="color: Red">*</span>
                </td>
                <td>
                    <input runat="server" type="text" id="Decisionmaker" onblur="IsChinese(this.value,'决策人','Decisionmaker')"
                        size="30" maxlength="30" name="Decisionmaker" style="width: 150px;" />
                </td>
                <td>
                    &nbsp;决策人手机：<span style="color: Red">*</span>
                </td>
                <td>
                    <input type="text" runat="server" id="DecisionTel" name="DecisionTel" 
                        onkeypress="return(event.keyCode>47&&event.keyCode<58)"
                        onpaste="return !clipboardData.getData('text').match(/\D/)"
                        maxlength="20" style="width: 150px;" />
                    <img id="btnDecisionTel" onclick="CheckDecisionTel()" title="检查决策人手机是否存在?" alt="检查决策人手机是否存在?"
                         src="../../Images/search01.png" style="cursor:hand; vertical-align:bottom;" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;决策人职位：
                </td>
                <td>
                    <input runat="server" type="text" id="DecisionPosition" onblur="IsChinese(this.value,'决策人职务','DecisionPosition')"
                        size="20" maxlength="20" name="DecisionPosition" style="width: 150px;" />
                </td>
                <td>
                    &nbsp;决策人性别：
                </td>
                <td>
                    <asp:DropDownList ID="DecisionSex" name="DecisionSex" runat="server" Width="160">
                        <asp:ListItem Value=""> </asp:ListItem>
                        <asp:ListItem Value="M">男</asp:ListItem>
                        <asp:ListItem Value="F">女</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;主营业务：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <input runat="server" type="text" id="CompanyProduct" name="CompanyProduct" size="100"
                        maxlength="100" style="width: 150px" />
                </td>
                <td>
                    &nbsp;公司电话1：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <input type="text" runat="server" id="Tel1" name="Tel1" onblur="IsTel(this.value,'公司电话1','Tel1')"
                        style="width: 150px;" />
                    <span class="span_font">格式:0755-12345678</span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;公司电话2：
                </td>
                <td>
                    <input type="text" runat="server" id="Tel2" name="Tel2" onblur="IsTel(this.value,'公司电话2','Tel2')"
                        style="width: 150px;" />
                    <span class="span_font">格式:0755-12345678</span>
                </td>
                <td>
                    &nbsp;决策人邮箱：
                </td>
                <td>
                    <input runat="server" type="text" id="DecisionEmail" name="DecisionEmail" onblur="isEmail(this.value,'决策人邮箱','DecisionEmail')"
                        style="width: 150px;" />
                    <span class="span_font">格式:name@example.com</span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;员工人数：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <asp:DropDownList ID="PersonId" runat="server" Width="160" AppendDataBoundItems="true">
                        <asp:ListItem Value=""></asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;客户区域：
                </td>
                <td>
                    <asp:DropDownList ID="AreaId" runat="server" Width="160" AppendDataBoundItems="true">
                        <asp:ListItem Value=""></asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;公司产值：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <asp:DropDownList ID="ProductId" runat="server" Width="160" AppendDataBoundItems="true">
                        <asp:ListItem Value=""></asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;所属行业：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <asp:DropDownList ID="TradeId" runat="server" Width="160" AppendDataBoundItems="true">
                        <asp:ListItem Value=""></asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;公司性质：
                </td>
                <td>
                    <asp:DropDownList ID="PropertyId" runat="server" Width="160" AppendDataBoundItems="true">
                        <asp:ListItem Value=""></asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;客户级别：
                </td>
                <td>
                    <asp:DropDownList ID="LevelId" runat="server" Width="160" AppendDataBoundItems="true">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;公司网站：
                </td>
                <td>
                    <input runat="server" type="text" id="CompanyNetting" name="CompanyNetting" style="width: 150px;" />
                </td>
                <td>
                    &nbsp;公司邮箱：
                </td>
                <td>
                    <input runat="server" type="text" size="30" maxlength="30" id="Email" name="Email"
                        onblur="isEmail(this.value,'公司邮箱','Email')" style="width: 150px;" />
                    <span class="span_font">格式:name@example.com</span>
                </td>
            </tr>
            <tr>
                <td colspan="6"><span style="color:Blue;">约场订单信息</span></td>
            </tr>
            <tr>
                <td>
                    &nbsp;场次费：<span style="color: Red">*</span>
                </td>
                <td>
                    <input type="text" runat="server" id="TotalMoney" name="TotalMoney" onkeyup="if(isNaN(value))execCommand('undo')"
                        onafterpaste="if(isNaN(value))execCommand('undo')" style="width: 150px;" />
                </td>
                <td>
                    &nbsp;推广讲师：<span style="color: Red">*</span>
                </td>
                <td>
                    <input type="hidden" id="TeacherId" name="TeacherId" runat="server" />
                    <input id="txtTeacherId" name="txtTeacherId" runat="server" readonly="readonly" type="text"
                        style="width: 150px; " />
                    <button id="btnTeacherId" name="Z" type="button" class="btnCheck" style="width: 50px;">
                        选择</button>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;讲场时间：<span style="color: Red">*</span>
                </td>
                <td>
                    <input id="txtTeacherTime" name="txtTeacherTime" readonly="readonly" 
                        runat="server" type="text" style="width: 150px;" />
                </td>
                <td>
                    &nbsp;讲场类型：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <asp:DropDownList ID="drpTeacherType" runat="server" Width="160">
                        <asp:ListItem Value=""> </asp:ListItem>
                        <asp:ListItem Value="A">上午</asp:ListItem>
                        <asp:ListItem Value="P">下午</asp:ListItem>
                        <asp:ListItem Value="N">晚上</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td colspan="6"><span style="color:Blue;">销售订单信息</span></td>
            </tr>
            <tr>
                <td>
                    &nbsp;业绩归属：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <input type="hidden" id="DeptId" name="DeptId" runat="server" />
                    <input id="txtDeptId" name="txtDeptId" runat="server" readonly="readonly" type="text"
                        style="width: 150px; " />
                    <button id="btnDeptId" name="G" type="button" class="btnCheck" style="width: 50px;">
                        选择</button>
                </td>
                <td>
                    &nbsp;预报人数：<%--<span style="color: Red">*</span>--%>
                </td>
                <td>
                    <input type="text" id="PersonNumber" name="PersonNumber" runat="server"
                        onkeyup="value=value.replace(/[^\d]/g,'')" 
                        onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
                        style="width: 150px; " />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;应收金额：<%--<span style="color: Red">*</span>--%>
                </td>
                <td colspan="3">
                    <input type="text" id="AccountReceivable" name="AccountReceivable" runat="server" onkeyup="if(isNaN(value))execCommand('undo')"
                        onafterpaste="if(isNaN(value))execCommand('undo')" style="width: 150px;" />
                </td>
                <td style="display:none;">
                    &nbsp;折扣率：<%--<span style="color: Red">*</span>--%>
                </td>
                <td style="display:none;">
                    <input type="text" id="Rebate" name="Rebate" runat="server" onkeyup="if(isNaN(value))execCommand('undo')"
                        onafterpaste="if(isNaN(value))execCommand('undo')" style="width: 150px;" />
                </td>
            </tr>
        </table>
    </div>
    <div id="dialog1" class="yui-pe-content">
        <div class="hd">
            客户信息</div>
        <div class="bd">
            <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    <div id="dialog2" class="yui-pe-content">
        <div class="hd">
            业绩归属</div>
        <div class="bd">
            <iframe id="EditUIWindow2" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    </form>
    <form id="form2" style="display: none" action="../../Extend/AjaxData/CustomOperating.aspx">
        <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    </form>
</body>
<script type="text/javascript">
    var btnSave = "", btnClose = "", vid = $("#ID").val(), state = "";
    var Url = "../../Extend/AjaxData/CustomOperating.aspx";
    var flag = "<%=Flag %>", type = "<%=Type %>", action = "<%=DataAction %>";
    var instance = [{ "ID": "", "Code": "", "AddUser": "", "SaleadviserId": "", "CustomerName": "",
        "Address": "", "State": "", "Province": "", "City": "", "Area": "", "Decisionmaker": "", "DecisionTel": "",
        "CompanyProduct": "", "Tel1": "", "PersonId": "", "AreaId": "", "ProductId": "", "TradeId": "",
        "TotalMoney": "", "TeachID": "", "HmDate": "", "HmType": "", "DeptId": "", "Amount": "",
        "AccountReceivable": "", "Rebate": ""
    }];
    (function () {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                    { position: 'top', height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                    { position: 'center', body: 'fieldForm', gutter: '1 1 1 1', scroll: true }
                    ]
            });
            layout.render();
        });

        $("#txtTeacherTime").cld();
        $('#Province').change(function () {
            var vProvince = $(this).children('option:selected').val();
            if (vProvince != "") {
                document.getElementById("City").options.length = 0;
                document.getElementById("Area").options.length = 0;
                $("#City").append("<option value=''>选择城市</option>");
                $("#Area").append("<option value=''>选择区县</option>");
                var vc = "ProvinceId='" + vProvince + "'";
                YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysCity&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        if (obj[i].Code != undefined || obj[i].Name != undefined) {
                                            $("#City").append("<option value='" + obj[i].Code + "'>" + obj[i].Name + "</option>");
                                        }
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
            }
        });
        $('#City').change(function () {
            var vCity = $('#City').children('option:selected').val();
            if (vCity != "") {
                document.getElementById("Area").options.length = 0;
                $("#Area").append("<option value=''>选择区县</option>");
                var vc = "CityId='" + vCity + "'";
                YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysArea&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        $("#Area").append($("<option></option>").val(obj[i].Name).html(obj[i].Name));
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
            }
        });
    })();
    //关闭当前页
    var fnClose = function () {
        window.parent.$("#tabs").tabs('close', '<%=PageTitle %>');
    }

    YAHOO.example.init = function () {
        function onButtonClick(p_oEvent) {
            switch (this.get("id")) {
                case "btnSave":
                    Save();
                    break;
                case "btnClose":
                    fnClose();
                    break;
                default:
                    break;
            }
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
            btnSave = new YAHOO.widget.Button("btnSave");
            btnSave.on("click", onButtonClick);
            btnClose = new YAHOO.widget.Button("btnClose");
            btnClose.on("click", onButtonClick);
        });
    } ();
    /*对应的方法和ID*/
    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow1").src = src;
        document.getElementById("yui-gen5-button").style.display = "block";
        YAHOO.example.container.dialog1.show();
    }
    //业绩归属选择对应的方法和ID
    var _fn, _id;
    function ShowDialog2(fn, id) {
        _fn = fn;
        _id = id;
        YAHOO.example.container.dialog2.show();
    }
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        var handleSubmit1 = function () {
            var editwindow = document.getElementById("EditUIWindow1");
            if (editwindow) {
                editwindow.contentWindow.ChooseInfo();
            }
            YAHOO.example.container.dialog1.hide();
        };
        var handleSubmit2 = function () {
            var editwindow = document.getElementById("EditUIWindow2");
            if (editwindow) {
                editwindow.contentWindow.ChooseInfo();
            }
            YAHOO.example.container.dialog2.hide();
        };
        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					        { width: "640px",
					            height: "300px",
					            fixedcenter: true,
					            visible: false,
					            draggable: true,
					            modal: true,
					            close: true,
					            autofillheight: "body",
					            constraintoviewport: true,
					            buttons: [{ text: "确定", handler: handleSubmit1, isDefault: true },
								        { text: "取消", handler: handleCancel}]
					        });
        YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
					            { width: "300px",
					                height: "400px",
					                fixedcenter: true,
					                visible: false,
					                draggable: true,
					                close: true,
					                autofillheight: "body",
					                constraintoviewport: true,
					                buttons: [{ text: "确定", handler: handleSubmit2, isDefault: true },
								            { text: "取消", handler: handleCancel}]
					            });
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog1.render();
        YAHOO.example.container.dialog2.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog2.render();
        //拖动大小dialog1
        var resize1 = new YAHOO.util.Resize("dialog1", {
            handles: ["br"],
            autoRatio: false,
            minWidth: 450,
            minHeight: 300,
            status: false
        });
        resize1.on("startResize", function (args) {
            if (this.cfg.getProperty("constraintoviewport")) {
                var D = YAHOO.util.Dom;
                var clientRegion = D.getClientRegion();
                var elRegion = D.getRegion(this.element);
                resize1.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
                resize1.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            } else {
                resize1.set("maxWidth", null);
                resize1.set("maxHeight", null);
            }

        }, YAHOO.example.container.dialog1, true);
        resize1.on("resize", function (args) {
            var panelHeight = args.height;
            this.cfg.setProperty("height", panelHeight + "px");
        }, YAHOO.example.container.dialog1, true);
        //拖动大小dialog2
        var resize2 = new YAHOO.util.Resize("dialog2", {
            handles: ["br"],
            autoRatio: false,
            minWidth: 300,
            minHeight: 250,
            status: false
        });
        resize2.on("startResize", function (args) {
            if (this.cfg.getProperty("constraintoviewport")) {
                var D = YAHOO.util.Dom;

                var clientRegion = D.getClientRegion();
                var elRegion = D.getRegion(this.element);

                resize2.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
                resize2.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            } else {
                resize2.set("maxWidth", null);
                resize2.set("maxHeight", null);
            }

        }, YAHOO.example.container.dialog1, true);
        resize2.on("resize", function (args) {
            var panelHeight = args.height;
            this.cfg.setProperty("height", panelHeight + "px");
        }, YAHOO.example.container.dialog2, true);
    });
    //检查客户名是否已存在
    function CheckCustomerName() {
        var vName = $('#CustomerName').val();
        if (vName != "") {
            YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerName&action=check&name=" + encodeURI(vName) + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {  //失败
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return;
                } else if (str == "1") {   //客户名称已经存在
                    //alert("该客户名称已经存在!");
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return;
                } else if (str == "11") {
                    //alert("该客户名称已经存在!");
                    state = "1";
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    LoadCustomerInfoSale(vName, "");
                    return;
                } else if (str == "2") {
                    alert("该客户名可以使用!");
                    $('#State').focus();
                    return;
                }
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
        } else {
            alert("客户名不能为空!");
            $('#CustomerName').focus();
        }
    }
    //检查决策人手机是否已存在
    function CheckDecisionTel() {
        var vDecisionTel = $('#DecisionTel').val();
        var vValue = vDecisionTel;
        if (vValue != "") {
            YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerTel&action=check&name=" + encodeURI(vValue) + "", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "0") {  //失败
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        return;
                    } else if (str == "1") {   //决策人手机已经存在
                        //alert("该决策人手机已经存在!");
                        document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=1&cn=" + encodeURI(vValue);
                        YAHOO.example.container.dialog1.show();
                        document.getElementById("yui-gen5-button").style.display = "none";
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        return;
                    } else if (str == "11") {
                        //alert("该决策人手机已经存在!");
                        state = "1";
                        document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=1&cn=" + encodeURI(vValue);
                        YAHOO.example.container.dialog1.show();
                        document.getElementById("yui-gen5-button").style.display = "none";
                        $('#DecisionTel').focus();
                        document.getElementById("DecisionTel").value = "";
                        LoadCustomerInfoSale("", vDecisionTel);
                        return;
                    } else if (str == "2") {
                        alert("该决策人手机可以使用!");
                        $('#CompanyProduct').focus();
                        return;
                    }
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
        } else {
            alert("决策人手机不能为空!");
            $('#DecisionTel').focus();
        }
    }
    var LoadCustomerInfoSale = function (vName, vTel) {
        var vc = "";
        if (vTel == "") {
            vc = "OriginId<>'62DBB228-9F0D-4CB8-9F5F-67D24929ADEC' and CustomerName='" + encodeURI(vName) + "'";
        }
        if (vName == "") {
            vc = "OriginId<>'62DBB228-9F0D-4CB8-9F5F-67D24929ADEC' and DecisionTel='" + encodeURI(vTel) + "'";
        }
        YAHOO.util.Connect.asyncRequest('GET', "../../Extend/AjaxData/JSONList.aspx?r=" + Math.random() + "&type=1&entity=V_CrmCustomerInfoSale&customCondition=" + vc + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                var obj = eval(str);
                vid = obj[0].ID;
                $("#Code").val(obj[0].Code);
                $("#AddUserId").val(obj[0].AddUser);
                $("#txtAddUserId").val(obj[0].AddUserName);
                $("#SaleadviserId").val(obj[0].SaleadviserId);
                $("#txtSaleadviserId").val(obj[0].SaleadviserName);
                $("#CustomerName").val(obj[0].CustomerName);
                /*$("#Province").each(function () {
                $(this).children("option").each(function () {
                if ($(this).text() == obj[0].Province) {
                $("#Province").append("<option value='" + obj[0].Province + "' selected>" + obj[0].Province + "</option>");
                }
                });
                });*/
                $("#Province").append("<option value='" + obj[0].Province + "' selected>" + obj[0].Province + "</option>");
                $("#City").append("<option value='" + obj[0].City + "' selected>" + obj[0].City + "</option>");
                $("#Area").append("<option value='" + obj[0].Area + "' selected>" + obj[0].Area + "</option>");
                $("#Address").val(obj[0].Address);
                if (obj[0].DecisionSex == "M") {
                    $("#DecisionSex").get(0).selectedIndex = 1;
                } else if (obj[0].DecisionSex == "F") {
                    $("#DecisionSex").get(0).selectedIndex = 2;
                }
                $("#Decisionmaker").val(obj[0].Decisionmaker);
                $("#DecisionTel").val(obj[0].DecisionTel);
                $("#CompanyProduct").val(obj[0].CompanyProduct);
                $("#Tel1").val(obj[0].Tel1);
                $("#DecisionPosition").val(obj[0].DecisionPosition);
                $("#Tel2").val(obj[0].Tel2);
                $("#DecisionEmail").val(obj[0].DecisionEmail);

                $("#PersonId").append("<option value='" + obj[0].PersonId + "' selected>" + obj[0].PersonName + "</option>");
                //$("#AreaId").append("<option value='" + obj[0].AreaId + "' selected>" + obj[0].AreaName + "</option>");
                $("#ProductId").append("<option value='" + obj[0].ProductId + "' selected>" + obj[0].ProductName + "</option>");
                $("#TradeId").append("<option value='" + obj[0].TradeId + "' selected>" + obj[0].TradeName + "</option>");
                $("#PropertyId").append("<option value='" + obj[0].PropertyId + "' selected>" + obj[0].PropertyName + "</option>");
                $("#LevelId").append("<option value='" + obj[0].LevelId + "' selected>" + obj[0].LevelName + "</option>");

                $("#CompanyNetting").val(obj[0].CompanyNetting);
                $("#Email").val(obj[0].Email);
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
    });
    }


    //保存
    function setValue() {
        instance[0].ID = vid;
        instance[0].Code = $("#Code").val();
        instance[0].AddUser = $("#AddUserId").val();
        instance[0].SaleadviserId = $("#SaleadviserId").val();
        instance[0].CustomerName = $('#CustomerName').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Address = $('#Address').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].State = $("#State").find("option:selected").text();
        instance[0].Province = $("#Province").find("option:selected").text();
        instance[0].City = $("#City").find("option:selected").text();
        instance[0].Area = $("#Area").find("option:selected").text();
        instance[0].Decisionmaker = $('#Decisionmaker').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].DecisionTel = $('#DecisionTel').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].DecisionPosition = $('#DecisionPosition').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].DecisionSex = $('#DecisionSex').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].CompanyProduct = $('#CompanyProduct').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Tel1 = $('#Tel1').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Tel2 = $('#Tel2').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].DecisionEmail = $('#DecisionEmail').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].PersonId = $('#PersonId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].AreaId = $('#AreaId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].ProductId = $('#ProductId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].TradeId = $('#TradeId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].PropertyId = $('#PropertyId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].LevelId = $('#LevelId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].CompanyNetting = $('#CompanyNetting').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Email = $('#Email').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].TotalMoney = $("#TotalMoney").val();
        instance[0].TeachID = $("#TeacherId").val();
        instance[0].HmDate = $("#txtTeacherTime").val();
        instance[0].HmType = $("#drpTeacherType").val();
        instance[0].DeptId = $("#DeptId").val();
        instance[0].Amount = $("#PersonNumber").val();
        instance[0].AccountReceivable = $("#AccountReceivable").val(); 
        instance[0].Rebate = $("#Rebate").val();
    }
    var Save = function () {
        setValue();
        if (instance[0].Code == "") {
            alert("客户编码不能为空!");
            $('#Code').focus();
            return;
        }
        if (instance[0].AddUser == "" || instance[0].AddUser == "00000000-0000-0000-0000-000000000000") {
            alert("信息专员不能为空!");
            $('#txtAddUserId').focus();
            return;
        }
        if (instance[0].SaleadviserId == "" || instance[0].SaleadviserId == "00000000-0000-0000-0000-000000000000") {
            alert("行销顾问不能为空!");
            $('#txtSaleadviserId').focus();
            return;
        }
        if (instance[0].CustomerName == "") {
            alert("客户名称不能为空!");
            $('#CustomerName').focus();
            return;
        }
        /*if (instance[0].Province == "" || instance[0].Province == "选择省份") {
            alert("省份不能为空!");
            $('#Province').focus();
            return;
        }
        if (instance[0].City == "" || instance[0].City == "选择城市") {
            alert("城市不能为空!");
            $('#City').focus();
            return;
        }*/
        if (instance[0].Province == "选择省份") {
            instance[0].Province = "";
        }
        if (instance[0].City == "选择城市") {
            instance[0].City = "";
        }
        if (instance[0].Area == "选择区县") {
            instance[0].Area = "";
        }
        /*if (instance[0].Address == "") {
            alert("地址不能为空!");
            $('#Address').focus();
            return;
        }*/
        if (instance[0].Decisionmaker == "") {
            alert("决策人不能为空!");
            $('#Decisionmaker').focus();
            return;
        }
        if (instance[0].Decisionmaker.length < 2) {
            alert("决策人姓名不能为单个汉字!");
            $('#Decisionmaker').focus();
            return;
        }
        if (instance[0].DecisionTel == "") {
            alert("决策人手机不能为空!");
            $('#DecisionTel').focus();
            return;
        }
        /*if (instance[0].CompanyProduct == "") {
            alert("主营业务不能为空!");
            $('#CompanyProduct').focus();
            return;
        }
        if (instance[0].Tel1 == "") {
            alert("公司电话1不能为空!");
            $('#Tel1').focus();
            return;
        }
        if (instance[0].PersonId == "" || instance[0].PersonId == null) {
            alert("员工人数不能为空!");
            $('#PersonId').focus();
            return;
        }
        if (instance[0].AreaId == "" || instance[0].AreaId == null) {
            instance[0].AreaId = "00000000-0000-0000-0000-000000000000";
            //alert("客户区域不能为空!");
            //$('#AreaId').focus();
            //return;
        }
        if (instance[0].ProductId == "" || instance[0].ProductId == null) {
            alert("公司产值不能为空!");
            $('#ProductId').focus();
            return;
        }
        if (instance[0].TradeId == "" || instance[0].TradeId == null) {
            alert("所属行业不能为空!");
            $('#TradeId').focus();
            return;
        }*/
        if (instance[0].TotalMoney == "" || instance[0].TotalMoney == null) {
            alert("场次费不能为空!");
            $('#TotalMoney').focus();
            return;
        }
        if (instance[0].TeachID == "" || instance[0].TeachID == null || instance[0].TeachID == "00000000-0000-0000-0000-000000000000") {
            alert("推广讲师不能为空!");
            $('#txtTeacherId').focus();
            return;
        }
        if (instance[0].HmDate == "" || instance[0].HmDate == null) {
            alert("讲场时间不能为空!");
            $('#txtTeacherTime').focus();
            return;
        }
        /*if (instance[0].HmType == "" || instance[0].HmType == null) {
            alert("讲场类型不能为空!");
            $('#drpTeacherType').focus();
            return;
        }*/
        /*if (instance[0].DeptId == "" || instance[0].DeptId == null || instance[0].DeptId == "00000000-0000-0000-0000-000000000000") {
            alert("业绩归属不能为空!");
            $('#txtDeptId').focus();
            return;
        }
        if (instance[0].Amount == "" || instance[0].Amount == null) {
            alert("成交人数不能为空!");
            $('#PersonNumber').focus();
            return;
        }
        if (instance[0].AccountReceivable == "" || instance[0].AccountReceivable == null) {
            alert("应收金额不能为空!");
            $('#AccountReceivable').focus();
            return;
        }
        if (instance[0].Rebate == "" || instance[0].Rebate == null) {
            alert("折扣率不能为空!");
            $('#Rebate').focus();
            return;
        }*/
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        $("#jsonDataContent").val(json);
        if (state == "1") {
            trySave();
        } else {
            CheckData();
        }
    }
    //保存数据验证
    function CheckData() {
        var vName = $('#CustomerName').val();
        var vDecisionmaker = $('#Decisionmaker').val();
        var vDecisionTel = $('#DecisionTel').val();
        var vValue = vName + "," + vDecisionmaker + "," + vDecisionTel;
        YAHOO.util.Connect.asyncRequest('POST', Url + "?r=" + Math.random() + "&id=" + vid + "&temp=" + flag + "&entity=CustomerName&action=check&name=" + encodeURI(vValue) + "", //条件 
        {success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {   //失败
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return false;
                } else if (str == "1") {  //客户名已存在
                    //alert("该客户名称已经存在!");
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    return false;
                } else if (str == "11") {
                    //alert("该客户名称已经存在!");
                    state = "1";
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=0&cn=" + encodeURI(vName);
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#CustomerName').focus();
                    document.getElementById("CustomerName").value = "";
                    LoadCustomerInfoSale(vName, "");
                    return false;
                } else if (str == "3") {  //决策人和决策人手机已经存在
                    //alert("决策人手机已经存在!");
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerShow&order=Code&ct=1&cn=" + vDecisionTel;
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#Decisionmaker').focus();
                    document.getElementById("DecisionTel").value = "";
                    return false;
                } else if (str == "33") {
                    //alert("决策人手机已经存在!");
                    state = "1";
                    document.getElementById("EditUIWindow1").src = "../../EditWidows/SubjectList.aspx?r=" + Math.random() + "&entity=V_CrmCustomerInfoSale&order=Code&ct=1&cn=" + vDecisionTel;
                    YAHOO.example.container.dialog1.show();
                    document.getElementById("yui-gen5-button").style.display = "none";
                    $('#Decisionmaker').focus();
                    document.getElementById("DecisionTel").value = "";
                    LoadCustomerInfoSale("", vDecisionTel);
                    return false;
                } else if (str == "4" || str == "5") {  //成功
                    trySave(); //保存数据方法
                }
                /*else if (str == "5") {
                alert("您今天录入的客户总数已超过设置的客户总数，如有疑问请联系管理员!");
                fnClose();
                RefreshDataParent();
                }*/
                return false;
            }
            catch (e) {
                return false;
            }
            finally {
            }
        }, failure: function () { }
    });
    }
    var trySave = function () {
        var formObject = document.getElementById('form2');
        YAHOO.util.Connect.setForm(formObject);
        var cObj = YAHOO.util.Connect.asyncRequest('POST', Url + "?flag=1&action=" + action + "&entity=CustomerHistory", callback);
    }
    var responseSuccess = function (res) {
        try {
            var str = res.responseText;
            if (str == "1") {
                alert("数据保存成功!");
                RefreshDataParent();
                window.location.href = "../Customer/AddHistoryCustomer.aspx?type=1&flag=1&entity=CrmCustomer&title=" + encodeURI("新增历史客户信息") + "";
            }
            else {
                alert(str);
            }
        } catch (e) {
        }
        finally {
        }
    };
    var responseFailure = function (error) {
        alert("数据错误：" + error.statusText);
    }
    var callback = {
        success: responseSuccess,
        failure: responseFailure
    }
    //刷新父窗体数据
    function RefreshDataParent() {
        if (parent.NeedRefreshPage != null) {
            if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
                parent.NeedRefreshPage.RefreshData();
            }
        }
    }
</script>
</html>
